//
//  LBSaomangCell.m
//  V-Learn
//
//  Created by Apple on 2019/1/1.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBSaomangCell.h"

@implementation LBSaomangCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifferCell = @"LBSaomangCell";
    LBSaomangCell *cell = [tableView dequeueReusableCellWithIdentifier:identifferCell];
    if (!cell) {
        cell = [[LBSaomangCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifferCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}
- (void)setupUI{
    self.icon = [[UIImageView alloc] init];
    self.icon.image = [UIImage imageNamed:@"wk_list_bgimg"];
    self.icon.layer.cornerRadius = 5;
    self.icon.layer.masksToBounds = YES;
    
    [self.contentView addSubview:self.icon];
    [self.icon makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15*kScaleFit);
        make.centerY.mas_equalTo(self.contentView);
//        make.top.mas_equalTo(7*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(165*kScaleFit, 100*kScaleFit));
    }];
    
    
    self.freeIcon = [[UIImageView alloc] init];

    self.freeIcon.image = [UIImage imageNamed:@"wk_saomang_free"];
    
    [self.icon addSubview:self.freeIcon];
    [self.freeIcon makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(-2*kScaleFit);
        make.right.mas_equalTo(-2*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(15*kScaleFit, 34*kScaleFit));
    }];
    
    self.freeIcon.hidden = YES;
    
    self.titleLab = [UILabel labelWithText:@"主题课程二级" andTextColor:rgb(51,51,51) andName:nil andFontSize:14*kScaleFit];
    [self.contentView addSubview:self.titleLab];
    [self.titleLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10*kScaleFit);
        make.top.mas_equalTo(self.icon.mas_top);
        make.right.mas_equalTo(-10*kScaleFit);
    }];
    
    self.detailLab = [UILabel labelWithText:@"激发孩子开口讲英语的兴趣，通过多元化的线上课堂，帮助孩子提升英语能力和综合素质。" andTextColor:rgb(51,51,51) andName:nil andFontSize:12*kScaleFit];
    [self.contentView addSubview:self.detailLab];
    self.detailLab.numberOfLines = 3;
    [self.detailLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10*kScaleFit);
        make.top.mas_equalTo(self.titleLab.mas_bottom).mas_equalTo(12*kScaleFit);
        make.right.mas_equalTo(-19*kScaleFit);
    }];
    
    self.priceLab = [UILabel labelWithText:@"￥699" andTextColor:rgb(233,38,18) andName:nil andFontSize:15*kScaleFit];
    [self.contentView addSubview:self.priceLab];
    self.priceLab.numberOfLines = 1;
    [self.priceLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10*kScaleFit);
        make.top.mas_equalTo(self.detailLab.mas_bottom).mas_equalTo(10);
//        make.right.mas_equalTo(-19*kScaleFit);
    }];
    
    self.contentView.userInteractionEnabled = YES;
    self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.deleteBtn  setImage:[UIImage imageNamed:@"wk_o"] forState:UIControlStateNormal];
    [self.deleteBtn  setImage:[UIImage imageNamed:@"wk_Selection"] forState:UIControlStateSelected];
    [self.deleteBtn addTarget:self action:@selector(clickDeleteBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.deleteBtn];
//    self.deleteBtn.hidden = YES;
    [self.deleteBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(-30);
        make.centerY.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
    
}

- (void)setCoursePackModel:(LBCoureseListModel *)coursePackModel{
    _coursePackModel = coursePackModel;
    self.titleLab.text = coursePackModel.packTitle;
    self.detailLab.text = coursePackModel.packagePresent;
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Public_URL,coursePackModel.imgUrl];
    NSURL *url = [NSURL URLWithString:urlString];
    [self.icon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
    self.priceLab.text = [NSString stringWithFormat:@"%@乐学币",coursePackModel.packagePrice];
    
}
- (void)setSaomangModel:(LBSaomiaoAreaModel *)saomangModel{
    _saomangModel = saomangModel;
    self.titleLab.text = saomangModel.courseName;
    self.detailLab.text = saomangModel.coursePresent;
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Public_URL,saomangModel.courseImage];
    NSURL *url = [NSURL URLWithString:urlString];
    [self.icon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
    self.priceLab.text = [NSString stringWithFormat:@"%@乐学币",saomangModel.coursePrice];
}
//我的课程
- (void)setMycourseListModel:(LBCourseOutputDTOListModel *)mycourseListModel{
    _mycourseListModel = mycourseListModel;
    self.titleLab.text = mycourseListModel.courseTitle;
    self.detailLab.text = mycourseListModel.courseName;
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Public_URL,mycourseListModel.courseImage];
    NSURL *url = [NSURL URLWithString:urlString];
    if ([mycourseListModel.courseType isEqualToString:@"2"]) {
        
    }
    self.priceLab.text = [NSString stringWithFormat:@"¥%@",mycourseListModel.coursePrice];
    [self.icon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
